<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>

    (function () {
        function Observer() {
            this.obj = {};
            this.on = (type, handler) => {
                this.obj[type] = (this.obj[type] ? this.obj[type] : []);
                this.obj[type].push(handler);
            }
            this.emit = (type, amg) => {
                if(this.obj[type]){
                    this.obj[type].forEach((item) => {
                        item(amg);
                    });
                }
            }
        }
        window.Observer = Observer;
    })()

    let oo = new Observer();

    oo.on('康迪迪',function(amg){console.log('小杨 收到 康迪迪的消息：' + amg);})
    oo.on('康迪迪',function(amg){console.log('小严 收到 康迪迪的消息：' + amg);})
    oo.emit('康迪迪','晚上九点开播！');

</script>